import time

import allure
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from advanced.page_objects.base_page import BasePage
from advanced.utils.web_util import click_exception


class CategoryCreatePage(BasePage):
    __INPUT_CATEGORY_NAME = (By.XPATH, "(//input[@class='el-input__inner'])[1]")
    __INPUT_NAME_CLICK = (By.XPATH, "(//input[@class='el-input__inner'])[2]")
    __BTN_CONFIRM = (By.CSS_SELECTOR, ".op-container .el-button--primary")
    """创建商品页面：创建商品"""
    @allure.step("创建商品")
    def create_category(self, phone, name):
        # 输入“商品编号”
        time.sleep(2)
        self.do_find(self.__INPUT_CATEGORY_NAME).click()
        time.sleep(2)
        self.do_send_keys(phone, self.__INPUT_CATEGORY_NAME)
        time.sleep(2)
        # 输入商品名称
        self.do_find(self.__INPUT_NAME_CLICK).click()
        time.sleep(2)
        self.do_send_keys(name, self.__INPUT_NAME_CLICK)
        time.sleep(2)
        # 点击“确定”按钮
        WebDriverWait(self.driver, 10).until(click_exception(*self.__BTN_CONFIRM))
        # self.driver.find_element(By.CSS_SELECTOR, '.op-container .el-button--primary').click()

        # ==》商品列表页面
        from advanced.page_objects.category_list_page import CategoryListPage
        return CategoryListPage(self.driver)
